﻿@using MVCMongo.Services
@model MVCMongo.ViewModel.ProfileIndexViewModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutProfile.cshtml";
}

@if (this.Model != null && this.Model.ChatModel.IsUserAuthenticated)
{
    <script type="text/javascript">
            $(function () {
                $.chat({
                    // your user information
                    user: {
                        Id: @this.Model.ChatModel.UserId,
                        Name: '@this.Model.ChatModel.UserName',
                        ProfilePictureUrl: '@Html.Raw(this.Model.ChatModel.UserProfilePictureUrl)'
                    },
                    // text displayed when the other user is typing
                    typingText: ' is typing...',
                    // the title for the user's list window
                    titleText: 'Chat',
                    // text displayed when there's no other users in the room
                    emptyRoomText: "There's no one around here. You can still open a session in another browser and chat with yourself :)",
                    // the adapter you are using
                    adapter: new SignalRAdapter() // new LongPollingAdapter()
                });
            });
    </script>
}
<div class="container-fluid">

    @Html.Partial("_PartialFriendFeed", Model.PostType)

    <div class="span3">
        @Html.Action("FriendList")


    </div>
</div>

<script>
    $("#txtMessage").blur(function() {
        var status = $(this).val();

        var isUrl = ValidUrl(status);

        if (isUrl) {

            var url = "@Url.Action("StreamData","Profile")?url=" + status;
            $.post(url, function(data) {
                // alert(data);
                $("#preview-display").css("display","block");

                $("#preview-display").html(data);

            });
        }
        return null;


    });
    function ValidUrl(str) {
        var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
        '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
        '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
        '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
        '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
        '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
        if(!pattern.test(str)) {
            return false;
        } else {
            return true;
        }
    }

</script>